package com.mysql.service;

import com.mysql.entity.Staffs;
import com.mysql.imples.Staffsimple;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 作者:wmx  2025-02-24 20:37
 * 1、功能；员工系统-业务层
 * 2、实现:
 * 3、参数
 **/
public class StaffsService {
    private  static Scanner scanner = new Scanner(System.in);
    private static Staffsimple staffsimple = new Staffsimple();

    private static int page = 0;

    /**
     * 功能:数据列表分页
     * @param staffs
     * @return
     */
    public static void StaffsDataRanderPage(List<Staffs> staffs, Long staffsCount){
        boolean flat = true;
        System.out.println("输入1:上一页 || 输入2:下一页 || 输入3:退出");
        while (flat){

            String outPage = scanner.nextLine();
            if(outPage.length() != 1 && outPage.length() != 2){
                System.out.println("指令输入有误");
            }else{
                int outPageInteger = Integer.parseInt(outPage);
                if (outPageInteger == 1) {
                       page--;
                       if(page<0) page = 0;

                } else if (outPageInteger == 2)  {
                      page++;
                }else if (outPageInteger == 3) {
                    flat = false;
                }else{
                    System.out.println("你输入的指令有误");
                }
                System.out.println(staffs.get(page).toString());
                System.out.println("总数"+staffsCount);
            }
        }
    }

    /**
     * 功能:添加学生数据
     */
    public  static  void StaffsInsertData(){
        System.out.println("请输入要添加的姓名");
        String name = scanner.nextLine();
        System.out.println("请输入要添加的年龄");
        int age = Integer.parseInt(scanner.nextLine());
        System.out.println("请输入要添加的联系方式");
        String phone = scanner.nextLine();
        System.out.println("请输入要添加的职业");
        String staPos = scanner.nextLine();
        Staffs staffs = new Staffs(name,age,phone,staPos);
        if(staffsimple.executeDateInsert(staffs) == 1){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
    }

    /**
     * 功能:删除学生数据
     */
    public  static  void StaffsDeletetData(){
        System.out.println("请输入要删除的学生id");
         int id = Integer.parseInt(scanner.nextLine());
        if(staffsimple.executeDateDelete(id) == 1){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }

    /**
     * 功能:修改学生数据
     */
    public  static  void StaffsUpdateDataCount(){
        System.out.println("请输入要修改的学生id");
        int id = Integer.parseInt(scanner.nextLine());
        System.out.println("请输入要添加的姓名");
        String name = scanner.nextLine();
        System.out.println("请输入要添加的年龄");
        int age = Integer.parseInt(scanner.nextLine());
        System.out.println("请输入要添加的联系方式");
        String phone = scanner.nextLine();
        System.out.println("请输入要添加的职业");
        String staPos = scanner.nextLine();
        Staffs staffs = new Staffs(id,name,age,phone,staPos,null,null);
        if(staffsimple.executeDateUpdate(staffs) == 1){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }

    /**
     * 功能:查询学生数据
     */
    public static  void StaffsUpdateData(){
        System.out.println("请输入要查询的学生的值");
        String parameter = scanner.nextLine();
        Long staffsCount = staffsimple.executeDataQueryCount(parameter);//查询学生的数据总数
        List<Staffs> staffs = staffsimple.executeDataQuery(parameter);//查询学生的数据

        System.out.println(staffs.get(0).toString());
        System.out.println("总数"+staffsCount);
        StaffsDataRanderPage(staffs, staffsCount);

    }
}
